package com.servlet.users;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.UsersDAO;
import com.entity.Users;

public class UpdateUsersByNameServlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String userName = request.getParameter("user_name");
		String userPassword = request.getParameter("user_password");
		
		Users users = new Users(userName,userPassword);
		users.setUser_password(userPassword);
		UsersDAO usersDAO = new UsersDAO();
		
		String msg = "失败";
		String returnPath = "/FindBookInfoByIdServlet?userName=" + userName;
		if (usersDAO.updateByName(users)) {
			msg = "成功";
			returnPath = "/FindAllBookInfoServlet";
		}
		//提示消息
		request.setAttribute("msg", "修改用户信息" + msg);
		//返回路径
		request.setAttribute("returnPath", returnPath);
		request.getRequestDispatcher("/background/message.jsp").forward(request, response);
		
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String userName = request.getParameter("user_name");
		String userPassword = request.getParameter("user_password");
		
		Users users = new Users(userName,userPassword);
		users.setUser_password(userPassword);
		UsersDAO usersDAO = new UsersDAO();
		
		String msg = "失败";
		String returnPath = "/FindBookInfoByIdServlet?userName=" + userName;
		if (usersDAO.updateByName(users)) {
			msg = "成功";
			returnPath = "/FindAllBookInfoServlet";
		}
		//提示消息
		request.setAttribute("msg", "修改用户信息" + msg);
		//返回路径
		request.setAttribute("returnPath", returnPath);
		request.getRequestDispatcher("/background/message.jsp").forward(request, response);
		
	}

}
